<template>
	
	<view>
		
        <web-view :src="link" v-if="link"/>
		<text style="text-align: center;color: red;" v-else>无效的地址</text>
	</view>
	
</template>

<script>
	
	import _hook from '../../common/_hook';
	
	export default {
		components: {
			
		},
		data() {
			return {
				link: false,
			}
		},
		onShow(){
			_hook.routeTabBarHook();
		},
		onLoad(option) {
			if('url' in option){
				option.url = decodeURIComponent(option.url);
				if(/^(?:http(s)?:\/\/)?[\w.-]+(?:\.[\w\.-]+)+[\w\-\._~:/?#[\]@!\$&'\*\+,;=.]+$/.test(option.url)){
					if(!/^http/.test(option.url)){
						option.url = 'https://' + option.url;
					}
					this.link = option.url;
				}
			}
		},
		computed: {
			
		},
		methods: {
			
		},
		onNavigationBarButtonTap(e) {
			
			// #ifdef APP-PLUS
			let pages = getCurrentPages()  
			let page = pages[pages.length - 1];  
			let currentPages = page.$getAppWebview()  
			let children = currentPages.children()
			let currentWebview = null
			if(children.length){
			    currentWebview = children[0]
			}
			// #endif
			
			switch (e.index){
				case 0:
					if(children.length===0){  
					    uni.navigateBack()  
					}else{  
					   children[0].close()  
					  setTimeout(()=>{  
					    uni.navigateBack()  
					  },80)  
					}
					break;
				case 1:
				
					// #ifdef APP-PLUS
						if(currentWebview) currentWebview.reload();
					// #endif
					
					// #ifdef H5
						location.reload();
					// #endif
					
					break;
				case 2:
				
					// #ifdef APP-PLUS
						if(currentWebview) currentWebview.forward();
					// #endif
					
					// #ifdef H5
						history.forward();
					// #endif
					
					break;
				default:
					break;
			}
		},
	}
</script>

<style>
	
</style>
